// Copyright (c) Lawrence Livermore National Security, LLC and other VisIt
// Project developers.  See the top-level LICENSE file for dates and other
// details.  No copyright assignment is required to contribute to VisIt.

#include <PyMaterialAttributes.h>
#include <ObserverToCallback.h>
#include <stdio.h>
#include <Py2and3Support.h>

// ****************************************************************************
// Module: PyMaterialAttributes
//
// Purpose:
//   Attributes to control material interface reconstruction
//
// Note:       Autogenerated by xml2python. Do not modify by hand!
//
// Programmer: xml2python
// Creation:   omitted
//
// ****************************************************************************

//
// This struct contains the Python type information and a MaterialAttributes.
//
struct MaterialAttributesObject
{
    PyObject_HEAD
    MaterialAttributes *data;
    bool        owns;
    PyObject   *parent;
};

//
// Internal prototypes
//
static PyObject *NewMaterialAttributes(int);
std::string
PyMaterialAttributes_ToString(const MaterialAttributes *atts, const char *prefix, const bool forLogging)
{
    std::string str;
    char tmpStr[1000];

    if(atts->GetSmoothing())
        snprintf(tmpStr, 1000, "%ssmoothing = 1\n", prefix);
    else
        snprintf(tmpStr, 1000, "%ssmoothing = 0\n", prefix);
    str += tmpStr;
    if(atts->GetForceMIR())
        snprintf(tmpStr, 1000, "%sforceMIR = 1\n", prefix);
    else
        snprintf(tmpStr, 1000, "%sforceMIR = 0\n", prefix);
    str += tmpStr;
    if(atts->GetCleanZonesOnly())
        snprintf(tmpStr, 1000, "%scleanZonesOnly = 1\n", prefix);
    else
        snprintf(tmpStr, 1000, "%scleanZonesOnly = 0\n", prefix);
    str += tmpStr;
    if(atts->GetNeedValidConnectivity())
        snprintf(tmpStr, 1000, "%sneedValidConnectivity = 1\n", prefix);
    else
        snprintf(tmpStr, 1000, "%sneedValidConnectivity = 0\n", prefix);
    str += tmpStr;
    const char *algorithm_names = "EquiT, EquiZ, Isovolume, PLIC, Discrete";
    switch (atts->GetAlgorithm())
    {
      case MaterialAttributes::EquiT:
          snprintf(tmpStr, 1000, "%salgorithm = %sEquiT  # %s\n", prefix, prefix, algorithm_names);
          str += tmpStr;
          break;
      case MaterialAttributes::EquiZ:
          snprintf(tmpStr, 1000, "%salgorithm = %sEquiZ  # %s\n", prefix, prefix, algorithm_names);
          str += tmpStr;
          break;
      case MaterialAttributes::Isovolume:
          snprintf(tmpStr, 1000, "%salgorithm = %sIsovolume  # %s\n", prefix, prefix, algorithm_names);
          str += tmpStr;
          break;
      case MaterialAttributes::PLIC:
          snprintf(tmpStr, 1000, "%salgorithm = %sPLIC  # %s\n", prefix, prefix, algorithm_names);
          str += tmpStr;
          break;
      case MaterialAttributes::Discrete:
          snprintf(tmpStr, 1000, "%salgorithm = %sDiscrete  # %s\n", prefix, prefix, algorithm_names);
          str += tmpStr;
          break;
      default:
          break;
    }

    if(atts->GetIterationEnabled())
        snprintf(tmpStr, 1000, "%siterationEnabled = 1\n", prefix);
    else
        snprintf(tmpStr, 1000, "%siterationEnabled = 0\n", prefix);
    str += tmpStr;
    snprintf(tmpStr, 1000, "%snumIterations = %d\n", prefix, atts->GetNumIterations());
    str += tmpStr;
    snprintf(tmpStr, 1000, "%siterationDamping = %g\n", prefix, atts->GetIterationDamping());
    str += tmpStr;
    if(atts->GetSimplifyHeavilyMixedZones())
        snprintf(tmpStr, 1000, "%ssimplifyHeavilyMixedZones = 1\n", prefix);
    else
        snprintf(tmpStr, 1000, "%ssimplifyHeavilyMixedZones = 0\n", prefix);
    str += tmpStr;
    snprintf(tmpStr, 1000, "%smaxMaterialsPerZone = %d\n", prefix, atts->GetMaxMaterialsPerZone());
    str += tmpStr;
    snprintf(tmpStr, 1000, "%sisoVolumeFraction = %g\n", prefix, atts->GetIsoVolumeFraction());
    str += tmpStr;
    snprintf(tmpStr, 1000, "%sannealingTime = %d\n", prefix, atts->GetAnnealingTime());
    str += tmpStr;
    return str;
}

static PyObject *
MaterialAttributes_Notify(PyObject *self, PyObject *args)
{
    MaterialAttributesObject *obj = (MaterialAttributesObject *)self;
    obj->data->Notify();
    Py_INCREF(Py_None);
    return Py_None;
}

/*static*/ PyObject *
MaterialAttributes_SetSmoothing(PyObject *self, PyObject *args)
{
    MaterialAttributesObject *obj = (MaterialAttributesObject *)self;

    PyObject *packaged_args = 0;

    // Handle args packaged into a tuple of size one
    // if we think the unpackaged args matches our needs
    if (PySequence_Check(args) && PySequence_Size(args) == 1)
    {
        packaged_args = PySequence_GetItem(args, 0);
        if (PyNumber_Check(packaged_args))
            args = packaged_args;
    }

    if (PySequence_Check(args))
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_TypeError, "expecting a single number arg");
    }

    if (!PyNumber_Check(args))
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_TypeError, "arg is not a number type");
    }

    long val = PyLong_AsLong(args);
    bool cval = bool(val);

    if (val == -1 && PyErr_Occurred())
    {
        Py_XDECREF(packaged_args);
        PyErr_Clear();
        return PyErr_Format(PyExc_TypeError, "arg not interpretable as C++ bool");
    }
    if (fabs(double(val))>1.5E-7 && fabs((double(long(cval))-double(val))/double(val))>1.5E-7)
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_ValueError, "arg not interpretable as C++ bool");
    }

    Py_XDECREF(packaged_args);

    // Set the smoothing in the object.
    obj->data->SetSmoothing(cval);

    Py_INCREF(Py_None);
    return Py_None;
}

/*static*/ PyObject *
MaterialAttributes_GetSmoothing(PyObject *self, PyObject *args)
{
    MaterialAttributesObject *obj = (MaterialAttributesObject *)self;
    PyObject *retval = PyInt_FromLong(obj->data->GetSmoothing()?1L:0L);
    return retval;
}

/*static*/ PyObject *
MaterialAttributes_SetForceMIR(PyObject *self, PyObject *args)
{
    MaterialAttributesObject *obj = (MaterialAttributesObject *)self;

    PyObject *packaged_args = 0;

    // Handle args packaged into a tuple of size one
    // if we think the unpackaged args matches our needs
    if (PySequence_Check(args) && PySequence_Size(args) == 1)
    {
        packaged_args = PySequence_GetItem(args, 0);
        if (PyNumber_Check(packaged_args))
            args = packaged_args;
    }

    if (PySequence_Check(args))
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_TypeError, "expecting a single number arg");
    }

    if (!PyNumber_Check(args))
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_TypeError, "arg is not a number type");
    }

    long val = PyLong_AsLong(args);
    bool cval = bool(val);

    if (val == -1 && PyErr_Occurred())
    {
        Py_XDECREF(packaged_args);
        PyErr_Clear();
        return PyErr_Format(PyExc_TypeError, "arg not interpretable as C++ bool");
    }
    if (fabs(double(val))>1.5E-7 && fabs((double(long(cval))-double(val))/double(val))>1.5E-7)
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_ValueError, "arg not interpretable as C++ bool");
    }

    Py_XDECREF(packaged_args);

    // Set the forceMIR in the object.
    obj->data->SetForceMIR(cval);

    Py_INCREF(Py_None);
    return Py_None;
}

/*static*/ PyObject *
MaterialAttributes_GetForceMIR(PyObject *self, PyObject *args)
{
    MaterialAttributesObject *obj = (MaterialAttributesObject *)self;
    PyObject *retval = PyInt_FromLong(obj->data->GetForceMIR()?1L:0L);
    return retval;
}

/*static*/ PyObject *
MaterialAttributes_SetCleanZonesOnly(PyObject *self, PyObject *args)
{
    MaterialAttributesObject *obj = (MaterialAttributesObject *)self;

    PyObject *packaged_args = 0;

    // Handle args packaged into a tuple of size one
    // if we think the unpackaged args matches our needs
    if (PySequence_Check(args) && PySequence_Size(args) == 1)
    {
        packaged_args = PySequence_GetItem(args, 0);
        if (PyNumber_Check(packaged_args))
            args = packaged_args;
    }

    if (PySequence_Check(args))
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_TypeError, "expecting a single number arg");
    }

    if (!PyNumber_Check(args))
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_TypeError, "arg is not a number type");
    }

    long val = PyLong_AsLong(args);
    bool cval = bool(val);

    if (val == -1 && PyErr_Occurred())
    {
        Py_XDECREF(packaged_args);
        PyErr_Clear();
        return PyErr_Format(PyExc_TypeError, "arg not interpretable as C++ bool");
    }
    if (fabs(double(val))>1.5E-7 && fabs((double(long(cval))-double(val))/double(val))>1.5E-7)
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_ValueError, "arg not interpretable as C++ bool");
    }

    Py_XDECREF(packaged_args);

    // Set the cleanZonesOnly in the object.
    obj->data->SetCleanZonesOnly(cval);

    Py_INCREF(Py_None);
    return Py_None;
}

/*static*/ PyObject *
MaterialAttributes_GetCleanZonesOnly(PyObject *self, PyObject *args)
{
    MaterialAttributesObject *obj = (MaterialAttributesObject *)self;
    PyObject *retval = PyInt_FromLong(obj->data->GetCleanZonesOnly()?1L:0L);
    return retval;
}

/*static*/ PyObject *
MaterialAttributes_SetNeedValidConnectivity(PyObject *self, PyObject *args)
{
    MaterialAttributesObject *obj = (MaterialAttributesObject *)self;

    PyObject *packaged_args = 0;

    // Handle args packaged into a tuple of size one
    // if we think the unpackaged args matches our needs
    if (PySequence_Check(args) && PySequence_Size(args) == 1)
    {
        packaged_args = PySequence_GetItem(args, 0);
        if (PyNumber_Check(packaged_args))
            args = packaged_args;
    }

    if (PySequence_Check(args))
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_TypeError, "expecting a single number arg");
    }

    if (!PyNumber_Check(args))
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_TypeError, "arg is not a number type");
    }

    long val = PyLong_AsLong(args);
    bool cval = bool(val);

    if (val == -1 && PyErr_Occurred())
    {
        Py_XDECREF(packaged_args);
        PyErr_Clear();
        return PyErr_Format(PyExc_TypeError, "arg not interpretable as C++ bool");
    }
    if (fabs(double(val))>1.5E-7 && fabs((double(long(cval))-double(val))/double(val))>1.5E-7)
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_ValueError, "arg not interpretable as C++ bool");
    }

    Py_XDECREF(packaged_args);

    // Set the needValidConnectivity in the object.
    obj->data->SetNeedValidConnectivity(cval);

    Py_INCREF(Py_None);
    return Py_None;
}

/*static*/ PyObject *
MaterialAttributes_GetNeedValidConnectivity(PyObject *self, PyObject *args)
{
    MaterialAttributesObject *obj = (MaterialAttributesObject *)self;
    PyObject *retval = PyInt_FromLong(obj->data->GetNeedValidConnectivity()?1L:0L);
    return retval;
}

/*static*/ PyObject *
MaterialAttributes_SetAlgorithm(PyObject *self, PyObject *args)
{
    MaterialAttributesObject *obj = (MaterialAttributesObject *)self;

    PyObject *packaged_args = 0;

    // Handle args packaged into a tuple of size one
    // if we think the unpackaged args matches our needs
    if (PySequence_Check(args) && PySequence_Size(args) == 1)
    {
        packaged_args = PySequence_GetItem(args, 0);
        if (PyNumber_Check(packaged_args))
            args = packaged_args;
    }

    if (PySequence_Check(args))
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_TypeError, "expecting a single number arg");
    }

    if (!PyNumber_Check(args))
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_TypeError, "arg is not a number type");
    }

    long val = PyLong_AsLong(args);
    int cval = int(val);

    if ((val == -1 && PyErr_Occurred()) || long(cval) != val)
    {
        Py_XDECREF(packaged_args);
        PyErr_Clear();
        return PyErr_Format(PyExc_TypeError, "arg not interpretable as C++ int");
    }

    if (cval < 0 || cval >= 5)
    {
        std::stringstream ss;
        ss << "An invalid algorithm value was given." << std::endl;
        ss << "Valid values are in the range [0,4]." << std::endl;
        ss << "You can also use the following symbolic names:";
        ss << " EquiT";
        ss << ", EquiZ";
        ss << ", Isovolume";
        ss << ", PLIC";
        ss << ", Discrete";
        return PyErr_Format(PyExc_ValueError, ss.str().c_str());
    }

    Py_XDECREF(packaged_args);

    // Set the algorithm in the object.
    obj->data->SetAlgorithm(MaterialAttributes::Algorithm(cval));

    Py_INCREF(Py_None);
    return Py_None;
}

/*static*/ PyObject *
MaterialAttributes_GetAlgorithm(PyObject *self, PyObject *args)
{
    MaterialAttributesObject *obj = (MaterialAttributesObject *)self;
    PyObject *retval = PyInt_FromLong(long(obj->data->GetAlgorithm()));
    return retval;
}

/*static*/ PyObject *
MaterialAttributes_SetIterationEnabled(PyObject *self, PyObject *args)
{
    MaterialAttributesObject *obj = (MaterialAttributesObject *)self;

    PyObject *packaged_args = 0;

    // Handle args packaged into a tuple of size one
    // if we think the unpackaged args matches our needs
    if (PySequence_Check(args) && PySequence_Size(args) == 1)
    {
        packaged_args = PySequence_GetItem(args, 0);
        if (PyNumber_Check(packaged_args))
            args = packaged_args;
    }

    if (PySequence_Check(args))
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_TypeError, "expecting a single number arg");
    }

    if (!PyNumber_Check(args))
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_TypeError, "arg is not a number type");
    }

    long val = PyLong_AsLong(args);
    bool cval = bool(val);

    if (val == -1 && PyErr_Occurred())
    {
        Py_XDECREF(packaged_args);
        PyErr_Clear();
        return PyErr_Format(PyExc_TypeError, "arg not interpretable as C++ bool");
    }
    if (fabs(double(val))>1.5E-7 && fabs((double(long(cval))-double(val))/double(val))>1.5E-7)
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_ValueError, "arg not interpretable as C++ bool");
    }

    Py_XDECREF(packaged_args);

    // Set the iterationEnabled in the object.
    obj->data->SetIterationEnabled(cval);

    Py_INCREF(Py_None);
    return Py_None;
}

/*static*/ PyObject *
MaterialAttributes_GetIterationEnabled(PyObject *self, PyObject *args)
{
    MaterialAttributesObject *obj = (MaterialAttributesObject *)self;
    PyObject *retval = PyInt_FromLong(obj->data->GetIterationEnabled()?1L:0L);
    return retval;
}

/*static*/ PyObject *
MaterialAttributes_SetNumIterations(PyObject *self, PyObject *args)
{
    MaterialAttributesObject *obj = (MaterialAttributesObject *)self;

    PyObject *packaged_args = 0;

    // Handle args packaged into a tuple of size one
    // if we think the unpackaged args matches our needs
    if (PySequence_Check(args) && PySequence_Size(args) == 1)
    {
        packaged_args = PySequence_GetItem(args, 0);
        if (PyNumber_Check(packaged_args))
            args = packaged_args;
    }

    if (PySequence_Check(args))
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_TypeError, "expecting a single number arg");
    }

    if (!PyNumber_Check(args))
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_TypeError, "arg is not a number type");
    }

    long val = PyLong_AsLong(args);
    int cval = int(val);

    if (val == -1 && PyErr_Occurred())
    {
        Py_XDECREF(packaged_args);
        PyErr_Clear();
        return PyErr_Format(PyExc_TypeError, "arg not interpretable as C++ int");
    }
    if (fabs(double(val))>1.5E-7 && fabs((double(long(cval))-double(val))/double(val))>1.5E-7)
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_ValueError, "arg not interpretable as C++ int");
    }

    Py_XDECREF(packaged_args);

    // Set the numIterations in the object.
    obj->data->SetNumIterations(cval);

    Py_INCREF(Py_None);
    return Py_None;
}

/*static*/ PyObject *
MaterialAttributes_GetNumIterations(PyObject *self, PyObject *args)
{
    MaterialAttributesObject *obj = (MaterialAttributesObject *)self;
    PyObject *retval = PyInt_FromLong(long(obj->data->GetNumIterations()));
    return retval;
}

/*static*/ PyObject *
MaterialAttributes_SetIterationDamping(PyObject *self, PyObject *args)
{
    MaterialAttributesObject *obj = (MaterialAttributesObject *)self;

    PyObject *packaged_args = 0;

    // Handle args packaged into a tuple of size one
    // if we think the unpackaged args matches our needs
    if (PySequence_Check(args) && PySequence_Size(args) == 1)
    {
        packaged_args = PySequence_GetItem(args, 0);
        if (PyNumber_Check(packaged_args))
            args = packaged_args;
    }

    if (PySequence_Check(args))
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_TypeError, "expecting a single number arg");
    }

    if (!PyNumber_Check(args))
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_TypeError, "arg is not a number type");
    }

    double val = PyFloat_AsDouble(args);
    float cval = float(val);

    if (val == -1 && PyErr_Occurred())
    {
        Py_XDECREF(packaged_args);
        PyErr_Clear();
        return PyErr_Format(PyExc_TypeError, "arg not interpretable as C++ float");
    }
    if (fabs(double(val))>1.5E-7 && fabs((double(double(cval))-double(val))/double(val))>1.5E-7)
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_ValueError, "arg not interpretable as C++ float");
    }

    Py_XDECREF(packaged_args);

    // Set the iterationDamping in the object.
    obj->data->SetIterationDamping(cval);

    Py_INCREF(Py_None);
    return Py_None;
}

/*static*/ PyObject *
MaterialAttributes_GetIterationDamping(PyObject *self, PyObject *args)
{
    MaterialAttributesObject *obj = (MaterialAttributesObject *)self;
    PyObject *retval = PyFloat_FromDouble(double(obj->data->GetIterationDamping()));
    return retval;
}

/*static*/ PyObject *
MaterialAttributes_SetSimplifyHeavilyMixedZones(PyObject *self, PyObject *args)
{
    MaterialAttributesObject *obj = (MaterialAttributesObject *)self;

    PyObject *packaged_args = 0;

    // Handle args packaged into a tuple of size one
    // if we think the unpackaged args matches our needs
    if (PySequence_Check(args) && PySequence_Size(args) == 1)
    {
        packaged_args = PySequence_GetItem(args, 0);
        if (PyNumber_Check(packaged_args))
            args = packaged_args;
    }

    if (PySequence_Check(args))
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_TypeError, "expecting a single number arg");
    }

    if (!PyNumber_Check(args))
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_TypeError, "arg is not a number type");
    }

    long val = PyLong_AsLong(args);
    bool cval = bool(val);

    if (val == -1 && PyErr_Occurred())
    {
        Py_XDECREF(packaged_args);
        PyErr_Clear();
        return PyErr_Format(PyExc_TypeError, "arg not interpretable as C++ bool");
    }
    if (fabs(double(val))>1.5E-7 && fabs((double(long(cval))-double(val))/double(val))>1.5E-7)
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_ValueError, "arg not interpretable as C++ bool");
    }

    Py_XDECREF(packaged_args);

    // Set the simplifyHeavilyMixedZones in the object.
    obj->data->SetSimplifyHeavilyMixedZones(cval);

    Py_INCREF(Py_None);
    return Py_None;
}

/*static*/ PyObject *
MaterialAttributes_GetSimplifyHeavilyMixedZones(PyObject *self, PyObject *args)
{
    MaterialAttributesObject *obj = (MaterialAttributesObject *)self;
    PyObject *retval = PyInt_FromLong(obj->data->GetSimplifyHeavilyMixedZones()?1L:0L);
    return retval;
}

/*static*/ PyObject *
MaterialAttributes_SetMaxMaterialsPerZone(PyObject *self, PyObject *args)
{
    MaterialAttributesObject *obj = (MaterialAttributesObject *)self;

    PyObject *packaged_args = 0;

    // Handle args packaged into a tuple of size one
    // if we think the unpackaged args matches our needs
    if (PySequence_Check(args) && PySequence_Size(args) == 1)
    {
        packaged_args = PySequence_GetItem(args, 0);
        if (PyNumber_Check(packaged_args))
            args = packaged_args;
    }

    if (PySequence_Check(args))
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_TypeError, "expecting a single number arg");
    }

    if (!PyNumber_Check(args))
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_TypeError, "arg is not a number type");
    }

    long val = PyLong_AsLong(args);
    int cval = int(val);

    if (val == -1 && PyErr_Occurred())
    {
        Py_XDECREF(packaged_args);
        PyErr_Clear();
        return PyErr_Format(PyExc_TypeError, "arg not interpretable as C++ int");
    }
    if (fabs(double(val))>1.5E-7 && fabs((double(long(cval))-double(val))/double(val))>1.5E-7)
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_ValueError, "arg not interpretable as C++ int");
    }

    Py_XDECREF(packaged_args);

    // Set the maxMaterialsPerZone in the object.
    obj->data->SetMaxMaterialsPerZone(cval);

    Py_INCREF(Py_None);
    return Py_None;
}

/*static*/ PyObject *
MaterialAttributes_GetMaxMaterialsPerZone(PyObject *self, PyObject *args)
{
    MaterialAttributesObject *obj = (MaterialAttributesObject *)self;
    PyObject *retval = PyInt_FromLong(long(obj->data->GetMaxMaterialsPerZone()));
    return retval;
}

/*static*/ PyObject *
MaterialAttributes_SetIsoVolumeFraction(PyObject *self, PyObject *args)
{
    MaterialAttributesObject *obj = (MaterialAttributesObject *)self;

    PyObject *packaged_args = 0;

    // Handle args packaged into a tuple of size one
    // if we think the unpackaged args matches our needs
    if (PySequence_Check(args) && PySequence_Size(args) == 1)
    {
        packaged_args = PySequence_GetItem(args, 0);
        if (PyNumber_Check(packaged_args))
            args = packaged_args;
    }

    if (PySequence_Check(args))
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_TypeError, "expecting a single number arg");
    }

    if (!PyNumber_Check(args))
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_TypeError, "arg is not a number type");
    }

    double val = PyFloat_AsDouble(args);
    float cval = float(val);

    if (val == -1 && PyErr_Occurred())
    {
        Py_XDECREF(packaged_args);
        PyErr_Clear();
        return PyErr_Format(PyExc_TypeError, "arg not interpretable as C++ float");
    }
    if (fabs(double(val))>1.5E-7 && fabs((double(double(cval))-double(val))/double(val))>1.5E-7)
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_ValueError, "arg not interpretable as C++ float");
    }

    Py_XDECREF(packaged_args);

    // Set the isoVolumeFraction in the object.
    obj->data->SetIsoVolumeFraction(cval);

    Py_INCREF(Py_None);
    return Py_None;
}

/*static*/ PyObject *
MaterialAttributes_GetIsoVolumeFraction(PyObject *self, PyObject *args)
{
    MaterialAttributesObject *obj = (MaterialAttributesObject *)self;
    PyObject *retval = PyFloat_FromDouble(double(obj->data->GetIsoVolumeFraction()));
    return retval;
}

/*static*/ PyObject *
MaterialAttributes_SetAnnealingTime(PyObject *self, PyObject *args)
{
    MaterialAttributesObject *obj = (MaterialAttributesObject *)self;

    PyObject *packaged_args = 0;

    // Handle args packaged into a tuple of size one
    // if we think the unpackaged args matches our needs
    if (PySequence_Check(args) && PySequence_Size(args) == 1)
    {
        packaged_args = PySequence_GetItem(args, 0);
        if (PyNumber_Check(packaged_args))
            args = packaged_args;
    }

    if (PySequence_Check(args))
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_TypeError, "expecting a single number arg");
    }

    if (!PyNumber_Check(args))
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_TypeError, "arg is not a number type");
    }

    long val = PyLong_AsLong(args);
    int cval = int(val);

    if (val == -1 && PyErr_Occurred())
    {
        Py_XDECREF(packaged_args);
        PyErr_Clear();
        return PyErr_Format(PyExc_TypeError, "arg not interpretable as C++ int");
    }
    if (fabs(double(val))>1.5E-7 && fabs((double(long(cval))-double(val))/double(val))>1.5E-7)
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_ValueError, "arg not interpretable as C++ int");
    }

    Py_XDECREF(packaged_args);

    // Set the annealingTime in the object.
    obj->data->SetAnnealingTime(cval);

    Py_INCREF(Py_None);
    return Py_None;
}

/*static*/ PyObject *
MaterialAttributes_GetAnnealingTime(PyObject *self, PyObject *args)
{
    MaterialAttributesObject *obj = (MaterialAttributesObject *)self;
    PyObject *retval = PyInt_FromLong(long(obj->data->GetAnnealingTime()));
    return retval;
}



PyMethodDef PyMaterialAttributes_methods[MATERIALATTRIBUTES_NMETH] = {
    {"Notify", MaterialAttributes_Notify, METH_VARARGS},
    {"SetSmoothing", MaterialAttributes_SetSmoothing, METH_VARARGS},
    {"GetSmoothing", MaterialAttributes_GetSmoothing, METH_VARARGS},
    {"SetForceMIR", MaterialAttributes_SetForceMIR, METH_VARARGS},
    {"GetForceMIR", MaterialAttributes_GetForceMIR, METH_VARARGS},
    {"SetCleanZonesOnly", MaterialAttributes_SetCleanZonesOnly, METH_VARARGS},
    {"GetCleanZonesOnly", MaterialAttributes_GetCleanZonesOnly, METH_VARARGS},
    {"SetNeedValidConnectivity", MaterialAttributes_SetNeedValidConnectivity, METH_VARARGS},
    {"GetNeedValidConnectivity", MaterialAttributes_GetNeedValidConnectivity, METH_VARARGS},
    {"SetAlgorithm", MaterialAttributes_SetAlgorithm, METH_VARARGS},
    {"GetAlgorithm", MaterialAttributes_GetAlgorithm, METH_VARARGS},
    {"SetIterationEnabled", MaterialAttributes_SetIterationEnabled, METH_VARARGS},
    {"GetIterationEnabled", MaterialAttributes_GetIterationEnabled, METH_VARARGS},
    {"SetNumIterations", MaterialAttributes_SetNumIterations, METH_VARARGS},
    {"GetNumIterations", MaterialAttributes_GetNumIterations, METH_VARARGS},
    {"SetIterationDamping", MaterialAttributes_SetIterationDamping, METH_VARARGS},
    {"GetIterationDamping", MaterialAttributes_GetIterationDamping, METH_VARARGS},
    {"SetSimplifyHeavilyMixedZones", MaterialAttributes_SetSimplifyHeavilyMixedZones, METH_VARARGS},
    {"GetSimplifyHeavilyMixedZones", MaterialAttributes_GetSimplifyHeavilyMixedZones, METH_VARARGS},
    {"SetMaxMaterialsPerZone", MaterialAttributes_SetMaxMaterialsPerZone, METH_VARARGS},
    {"GetMaxMaterialsPerZone", MaterialAttributes_GetMaxMaterialsPerZone, METH_VARARGS},
    {"SetIsoVolumeFraction", MaterialAttributes_SetIsoVolumeFraction, METH_VARARGS},
    {"GetIsoVolumeFraction", MaterialAttributes_GetIsoVolumeFraction, METH_VARARGS},
    {"SetAnnealingTime", MaterialAttributes_SetAnnealingTime, METH_VARARGS},
    {"GetAnnealingTime", MaterialAttributes_GetAnnealingTime, METH_VARARGS},
    {NULL, NULL}
};

//
// Type functions
//

static void
MaterialAttributes_dealloc(PyObject *v)
{
   MaterialAttributesObject *obj = (MaterialAttributesObject *)v;
   if(obj->parent != 0)
       Py_DECREF(obj->parent);
   if(obj->owns)
       delete obj->data;
}

static PyObject *MaterialAttributes_richcompare(PyObject *self, PyObject *other, int op);
PyObject *
PyMaterialAttributes_getattr(PyObject *self, char *name)
{
    if(strcmp(name, "smoothing") == 0)
        return MaterialAttributes_GetSmoothing(self, NULL);
    if(strcmp(name, "forceMIR") == 0)
        return MaterialAttributes_GetForceMIR(self, NULL);
    if(strcmp(name, "cleanZonesOnly") == 0)
        return MaterialAttributes_GetCleanZonesOnly(self, NULL);
    if(strcmp(name, "needValidConnectivity") == 0)
        return MaterialAttributes_GetNeedValidConnectivity(self, NULL);
    if(strcmp(name, "algorithm") == 0)
        return MaterialAttributes_GetAlgorithm(self, NULL);
    if(strcmp(name, "EquiT") == 0)
        return PyInt_FromLong(long(MaterialAttributes::EquiT));
    if(strcmp(name, "EquiZ") == 0)
        return PyInt_FromLong(long(MaterialAttributes::EquiZ));
    if(strcmp(name, "Isovolume") == 0)
        return PyInt_FromLong(long(MaterialAttributes::Isovolume));
    if(strcmp(name, "PLIC") == 0)
        return PyInt_FromLong(long(MaterialAttributes::PLIC));
    if(strcmp(name, "Discrete") == 0)
        return PyInt_FromLong(long(MaterialAttributes::Discrete));

    if(strcmp(name, "iterationEnabled") == 0)
        return MaterialAttributes_GetIterationEnabled(self, NULL);
    if(strcmp(name, "numIterations") == 0)
        return MaterialAttributes_GetNumIterations(self, NULL);
    if(strcmp(name, "iterationDamping") == 0)
        return MaterialAttributes_GetIterationDamping(self, NULL);
    if(strcmp(name, "simplifyHeavilyMixedZones") == 0)
        return MaterialAttributes_GetSimplifyHeavilyMixedZones(self, NULL);
    if(strcmp(name, "maxMaterialsPerZone") == 0)
        return MaterialAttributes_GetMaxMaterialsPerZone(self, NULL);
    if(strcmp(name, "isoVolumeFraction") == 0)
        return MaterialAttributes_GetIsoVolumeFraction(self, NULL);
    if(strcmp(name, "annealingTime") == 0)
        return MaterialAttributes_GetAnnealingTime(self, NULL);


    // Add a __dict__ answer so that dir() works
    if (!strcmp(name, "__dict__"))
    {
        PyObject *result = PyDict_New();
        for (int i = 0; PyMaterialAttributes_methods[i].ml_meth; i++)
            PyDict_SetItem(result,
                PyString_FromString(PyMaterialAttributes_methods[i].ml_name),
                PyString_FromString(PyMaterialAttributes_methods[i].ml_name));
        return result;
    }

    return Py_FindMethod(PyMaterialAttributes_methods, self, name);
}

int
PyMaterialAttributes_setattr(PyObject *self, char *name, PyObject *args)
{
    PyObject NULL_PY_OBJ;
    PyObject *obj = &NULL_PY_OBJ;

    if(strcmp(name, "smoothing") == 0)
        obj = MaterialAttributes_SetSmoothing(self, args);
    else if(strcmp(name, "forceMIR") == 0)
        obj = MaterialAttributes_SetForceMIR(self, args);
    else if(strcmp(name, "cleanZonesOnly") == 0)
        obj = MaterialAttributes_SetCleanZonesOnly(self, args);
    else if(strcmp(name, "needValidConnectivity") == 0)
        obj = MaterialAttributes_SetNeedValidConnectivity(self, args);
    else if(strcmp(name, "algorithm") == 0)
        obj = MaterialAttributes_SetAlgorithm(self, args);
    else if(strcmp(name, "iterationEnabled") == 0)
        obj = MaterialAttributes_SetIterationEnabled(self, args);
    else if(strcmp(name, "numIterations") == 0)
        obj = MaterialAttributes_SetNumIterations(self, args);
    else if(strcmp(name, "iterationDamping") == 0)
        obj = MaterialAttributes_SetIterationDamping(self, args);
    else if(strcmp(name, "simplifyHeavilyMixedZones") == 0)
        obj = MaterialAttributes_SetSimplifyHeavilyMixedZones(self, args);
    else if(strcmp(name, "maxMaterialsPerZone") == 0)
        obj = MaterialAttributes_SetMaxMaterialsPerZone(self, args);
    else if(strcmp(name, "isoVolumeFraction") == 0)
        obj = MaterialAttributes_SetIsoVolumeFraction(self, args);
    else if(strcmp(name, "annealingTime") == 0)
        obj = MaterialAttributes_SetAnnealingTime(self, args);

    if (obj != NULL && obj != &NULL_PY_OBJ)
        Py_DECREF(obj);

    if (obj == &NULL_PY_OBJ)
    {
        obj = NULL;
        PyErr_Format(PyExc_NameError, "name '%s' is not defined", name);
    }
    else if (obj == NULL && !PyErr_Occurred())
        PyErr_Format(PyExc_RuntimeError, "unknown problem with '%s'", name);

    return (obj != NULL) ? 0 : -1;
}

static int
MaterialAttributes_print(PyObject *v, FILE *fp, int flags)
{
    MaterialAttributesObject *obj = (MaterialAttributesObject *)v;
    fprintf(fp, "%s", PyMaterialAttributes_ToString(obj->data, "",false).c_str());
    return 0;
}

PyObject *
MaterialAttributes_str(PyObject *v)
{
    MaterialAttributesObject *obj = (MaterialAttributesObject *)v;
    return PyString_FromString(PyMaterialAttributes_ToString(obj->data,"", false).c_str());
}

//
// The doc string for the class.
//
#if PY_MAJOR_VERSION > 2 || (PY_MAJOR_VERSION == 2 && PY_MINOR_VERSION >= 5)
static const char *MaterialAttributes_Purpose = "Attributes to control material interface reconstruction";
#else
static char *MaterialAttributes_Purpose = "Attributes to control material interface reconstruction";
#endif

//
// Python Type Struct Def Macro from Py2and3Support.h
//
//         VISIT_PY_TYPE_OBJ( VPY_TYPE,
//                            VPY_NAME,
//                            VPY_OBJECT,
//                            VPY_DEALLOC,
//                            VPY_PRINT,
//                            VPY_GETATTR,
//                            VPY_SETATTR,
//                            VPY_STR,
//                            VPY_PURPOSE,
//                            VPY_RICHCOMP,
//                            VPY_AS_NUMBER)

//
// The type description structure
//

VISIT_PY_TYPE_OBJ(MaterialAttributesType,         \
                  "MaterialAttributes",           \
                  MaterialAttributesObject,       \
                  MaterialAttributes_dealloc,     \
                  MaterialAttributes_print,       \
                  PyMaterialAttributes_getattr,   \
                  PyMaterialAttributes_setattr,   \
                  MaterialAttributes_str,         \
                  MaterialAttributes_Purpose,     \
                  MaterialAttributes_richcompare, \
                  0); /* as_number*/

//
// Helper function for comparing.
//
static PyObject *
MaterialAttributes_richcompare(PyObject *self, PyObject *other, int op)
{
    // only compare against the same type 
    if ( Py_TYPE(self) != &MaterialAttributesType
         || Py_TYPE(other) != &MaterialAttributesType)
    {
        Py_INCREF(Py_NotImplemented);
        return Py_NotImplemented;
    }

    PyObject *res = NULL;
    MaterialAttributes *a = ((MaterialAttributesObject *)self)->data;
    MaterialAttributes *b = ((MaterialAttributesObject *)other)->data;

    switch (op)
    {
       case Py_EQ:
           res = (*a == *b) ? Py_True : Py_False;
           break;
       case Py_NE:
           res = (*a != *b) ? Py_True : Py_False;
           break;
       default:
           res = Py_NotImplemented;
           break;
    }

    Py_INCREF(res);
    return res;
}

//
// Helper functions for object allocation.
//

static MaterialAttributes *defaultAtts = 0;
static MaterialAttributes *currentAtts = 0;

static PyObject *
NewMaterialAttributes(int useCurrent)
{
    MaterialAttributesObject *newObject;
    newObject = PyObject_NEW(MaterialAttributesObject, &MaterialAttributesType);
    if(newObject == NULL)
        return NULL;
    if(useCurrent && currentAtts != 0)
        newObject->data = new MaterialAttributes(*currentAtts);
    else if(defaultAtts != 0)
        newObject->data = new MaterialAttributes(*defaultAtts);
    else
        newObject->data = new MaterialAttributes;
    newObject->owns = true;
    newObject->parent = 0;
    return (PyObject *)newObject;
}

static PyObject *
WrapMaterialAttributes(const MaterialAttributes *attr)
{
    MaterialAttributesObject *newObject;
    newObject = PyObject_NEW(MaterialAttributesObject, &MaterialAttributesType);
    if(newObject == NULL)
        return NULL;
    newObject->data = (MaterialAttributes *)attr;
    newObject->owns = false;
    newObject->parent = 0;
    return (PyObject *)newObject;
}

///////////////////////////////////////////////////////////////////////////////
//
// Interface that is exposed to the VisIt module.
//
///////////////////////////////////////////////////////////////////////////////

PyObject *
MaterialAttributes_new(PyObject *self, PyObject *args)
{
    int useCurrent = 0;
    if (!PyArg_ParseTuple(args, "i", &useCurrent))
    {
        if (!PyArg_ParseTuple(args, ""))
            return NULL;
        else
            PyErr_Clear();
    }

    return (PyObject *)NewMaterialAttributes(useCurrent);
}

//
// Plugin method table. These methods are added to the visitmodule's methods.
//
static PyMethodDef MaterialAttributesMethods[] = {
    {"MaterialAttributes", MaterialAttributes_new, METH_VARARGS},
    {NULL,      NULL}        /* Sentinel */
};

static Observer *MaterialAttributesObserver = 0;

std::string
PyMaterialAttributes_GetLogString()
{
    std::string s("MaterialAtts = MaterialAttributes()\n");
    if(currentAtts != 0)
        s += PyMaterialAttributes_ToString(currentAtts, "MaterialAtts.", true);
    return s;
}

static void
PyMaterialAttributes_CallLogRoutine(Subject *subj, void *data)
{
    typedef void (*logCallback)(const std::string &);
    logCallback cb = (logCallback)data;

    if(cb != 0)
    {
        std::string s("MaterialAtts = MaterialAttributes()\n");
        s += PyMaterialAttributes_ToString(currentAtts, "MaterialAtts.", true);
        cb(s);
    }
}

void
PyMaterialAttributes_StartUp(MaterialAttributes *subj, void *data)
{
    if(subj == 0)
        return;

    currentAtts = subj;
    PyMaterialAttributes_SetDefaults(subj);

    //
    // Create the observer that will be notified when the attributes change.
    //
    if(MaterialAttributesObserver == 0)
    {
        MaterialAttributesObserver = new ObserverToCallback(subj,
            PyMaterialAttributes_CallLogRoutine, (void *)data);
    }

}

void
PyMaterialAttributes_CloseDown()
{
    delete defaultAtts;
    defaultAtts = 0;
    delete MaterialAttributesObserver;
    MaterialAttributesObserver = 0;
}

PyMethodDef *
PyMaterialAttributes_GetMethodTable(int *nMethods)
{
    *nMethods = 1;
    return MaterialAttributesMethods;
}

bool
PyMaterialAttributes_Check(PyObject *obj)
{
    return (obj->ob_type == &MaterialAttributesType);
}

MaterialAttributes *
PyMaterialAttributes_FromPyObject(PyObject *obj)
{
    MaterialAttributesObject *obj2 = (MaterialAttributesObject *)obj;
    return obj2->data;
}

PyObject *
PyMaterialAttributes_New()
{
    return NewMaterialAttributes(0);
}

PyObject *
PyMaterialAttributes_Wrap(const MaterialAttributes *attr)
{
    return WrapMaterialAttributes(attr);
}

void
PyMaterialAttributes_SetParent(PyObject *obj, PyObject *parent)
{
    MaterialAttributesObject *obj2 = (MaterialAttributesObject *)obj;
    obj2->parent = parent;
}

void
PyMaterialAttributes_SetDefaults(const MaterialAttributes *atts)
{
    if(defaultAtts)
        delete defaultAtts;

    defaultAtts = new MaterialAttributes(*atts);
}

